(function(window) {
    
    var jsObj = {};
    window.jsObj = jsObj;
    let NEDWebViewGetFunc = "nedGetFunc";
    let NEDWebViewFuncAppInfo = "appInfo";
    var iosAppInfo = "";
    
    var iosBridge = {};
    //获取用户信息
    jsObj.appInfo = function () {
//         console.log('appinfo ==' + iosAppInfo);
        if(iosAppInfo){
            return iosAppInfo;
        }
        var result = window.prompt(NEDWebViewGetFunc,NEDWebViewFuncAppInfo);
        return result;
    }
    function setupWebViewJavascriptBridge(callback) {
        if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
        if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
        window.WVJBCallbacks = [callback];
        var WVJBIframe = document.createElement('iframe');
        WVJBIframe.style.display = 'none';
        WVJBIframe.src = 'https://__bridge_loaded__';
        document.documentElement.appendChild(WVJBIframe);
        setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
    }
    setupWebViewJavascriptBridge(function(bridge) {
        iosBridge = bridge;
        bridge.callHandler('appInfo', function(response) {
            iosAppInfo = response;
        })
//         window.jsObj.appInfo = function (){
//             console.log('appinfo');
//             var ainfo = iosBridge.callHandler('appInfo', function(response) {
//                 console.log('appinfo get ' + response);
//                 return response;
//             })
//             console.log('appinfo return ' + ainfo);
//             return ainfo;
//         })
        window.jsObj.routerPath = function (url){
            bridge.callHandler('routerPath', url, function(response) {
                
            })
        };
        window.jsObj.closeWeb = function (){
            bridge.callHandler('closeWeb', function(response) {

            })
        };
        window.jsObj.reloadH5 = function (){
            bridge.callHandler('reloadH5', function(response) {
            })
        };
        window.jsObj.goBack = function (){
            bridge.callHandler('goBack', function(response) {
            })
        };
        window.jsObj.isInterceptBack = function (flag){
            bridge.callHandler('isInterceptBack', flag, function(response) {
            })
        };
        window.jsObj.secondaryPage = function (url, title){
            var params = {
                'url':url,
                'title':title,
            };
            bridge.callHandler('secondaryPage', params, function(response) {
            })
        };
        window.jsObj.postPointInfo = function (eventId, msg){
            var params = {
                'eventId':eventId,
                'msg':msg,
            };
            bridge.callHandler('postPointInfo', params, function(response) {
            })
        };
        window.jsObj.clickCallback = function (eventId, msg){
            var params = {
                'eventId':eventId,
                'msg':msg,
            };
            bridge.callHandler('clickCallback', params, function(response) {
            })
        };
        window.jsObj.toast = function (msg){
            bridge.callHandler('toast', msg, function(response) {
            })
        };
        mb_log = function (msg){
            bridge.callHandler('mb_log', msg, function(response) {
                callback(response);
            })
        };
    });
})(window);
